/*
 *
 * Copyright (c) 2020-2022, Java知识图谱 (http://www.altitude.xin).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package xin.altitude.db.redis.sync.config;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import xin.altitude.cms.common.util.RedisUtils;
import xin.altitude.db.redis.sync.service.impl.OrderServiceImpl;

import java.io.IOException;


/**
 * @author explore
 * @since 2022/03/04 18:54
 **/
@Component
@Slf4j
public class OrderReceiver {
    /**
     * 模拟监听消息队列
     *
     * @param channel
     * @param message
     */
    @RabbitListener(queues = RabbitmqConfig.DELAY_QUEUE_NAME)
    public void consumeNode01(Channel channel, Message message, Long orderId) throws IOException {
        /* 删除Redis中缓存数据(幂等性，不用考虑重复消费问题) */
        RedisUtils.deleteObject(OrderServiceImpl.ORDER_KEY_PREFIX + orderId);
        log.info("A:" + orderId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
